import requests

from common.get_id import get_department_id
from common.get_token import get_login_token


class DepartmentApi(object):

    @staticmethod
    def post_department(token, json_data):
        return requests.post(url="http://ihrm-test.itheima.net/api/company/department",
                             headers={"Authorization": token}, json=json_data)

    @staticmethod
    def put_department(department_id, token, json_data):
        return requests.put(url="http://ihrm-test.itheima.net/api/company/department/" + department_id,
                            headers={"Authorization": token}, json=json_data)

    @staticmethod
    def get_department(department_id, token):
        return requests.get(url="http://ihrm-test.itheima.net/api/company/department/" + department_id,
                            headers={"Authorization": token})

    @staticmethod
    def delete_department(department_id, token):
        return requests.delete(url="http://ihrm-test.itheima.net/api/company/department/" + department_id,
                               headers={"Authorization": token})


if __name__ == '__main__':
    token = get_login_token()
    department_id = get_department_id()

    post_data = {"name": "Test部门", "code": "66778899"}
    resp = DepartmentApi.post_department(token, post_data)
    print("部门添加", resp.json())

    put_data = {"name": "测试部门", "code": "66778899"}
    resp = DepartmentApi.put_department(department_id, token, put_data)
    print("部门修改", resp.json())

    resp = DepartmentApi.get_department(department_id, token)
    print("获取部门信息", resp.json())

    resp = DepartmentApi.delete_department(department_id, token)
    print("删除部门", resp.json())
